package com.yy.chapter7.controller;

import com.yy.chapter7.exception.MyException;
import com.yy.chapter7.service.UserService;
import com.yy.chapter7.vo.ResponseVo;
import com.yy.chapter7.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yangyao
 * @Description: TODO
 * @date 2018/10/24 09:20
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据userName查询用户信息
     * @param userName
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getUserInfoByUserName")
    public User getUserInfoByUserName(String userName) throws Exception{
        if (1==1) {
            throw new MyException(new ResponseVo(100,"错误，自定义异常信息"));
        }
        return this.userService.findByUserName(userName);
    }

    /**
     * 查询所有User信息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getAll")
    public List<User> getAll() throws Exception{
        int a = 1/0;
        return  this.userService.findAll();
    }
}
